package com.code.zjm.binder.demo.entity;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * Created by ZJM on 2017/3/16.
 */

public class Student implements Parcelable {
    private int studentId;
    private String name;
    private List<Book> books;

    /**
     * 空构造器
     */
    public Student() {

    }

    /**
     * 初始化参数构造器
     *
     * @param studentId 学生id
     * @param name      学生姓名
     * @param books     书籍
     */
    public Student(int studentId, String name, List<Book> books) {
        this.studentId = studentId;
        this.name = name;
        this.books = books;
    }


    private Student(Parcel in) {
        studentId = in.readInt();
        name = in.readString();
        books = in.createTypedArrayList(Book.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(studentId);
        dest.writeString(name);
        dest.writeTypedList(books);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Student> CREATOR = new Creator<Student>() {
        @Override
        public Student createFromParcel(Parcel in) {
            return new Student(in);
        }

        @Override
        public Student[] newArray(int size) {
            return new Student[size];
        }
    };

    private int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Book> getBooks() {
        return books;
    }

    public void setBooks(List<Book> books) {
        this.books = books;
    }

    @Override
    public String toString() {
        return getStudentId() + "：" + getName(); //注意不要使用 '',会自动转换成数字
    }
}
